-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go/feature/shared ssa library #19011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
owen-mc
wants to merge
24
commits into
github:main
Choose a base branch
from
owen-mc:go/feature/shared-ssa-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…implement. Queries / tests that required changes: * The CleartextLogging and MissingErrorCheck queries are updated because they assumed def-use flow * The CommandInjection query works around the shortcomings of use-use flow by essentially reintroducing def-use flow when it applies a sanitizer * The OpenUrlRedirect query currently just accepts its fate; the tests are updated to avoid excess sanitization while the query comments on the problem. We should choose this approach or the CommandInjection one.
No changes in functionality.
Without this change the test go/ql/test/query-tests/InconsistentCode/UnhandledCloseWritableHandle/UnhandledCloseWritableHandle.qlref was failing.
Make it sanitize the result of the call rather than the input, so that further uses of the input are still tainted. This means that it catches things like `log.Print(fmt.Sprintf("user %q logged in.\n", username))` where the argument to the LoggerCall contains a StringFormatCall, but it misses things like `log.Printf("user %q logged in.\n", username)`. So we extract the logic into a predicate and apply it as a condition in the sink as well. The downside of this approach is that if there are two tainted inputs and only one has a safe format argument then we still sanitize the result. Hopefully this is rare.
We have an operator expression like `x * 5`. We want to follow where the value of the operator expression goes. We used to follow local flow from an operand, but now there is flow from that operand to the next use of the variable. The fix is to explicitly start local flow from the operator expression. There are also some expected edge changes due to use-use flow.
We were assuming that `sink` only had one successor, the TypeCastNode, but it can now have an adjacent use as well.
By moving it from the expression evaluation to the type assertion evaluation we don't block flow to successor uses of the same variable.
Match the order used in the shared SSA library
efc9483
to
d98a669
Compare
d98a669
to
d49f05f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is based on #14751, which switches to use-use flow without adopting the shared SSA library.
This is not quite finished. So far it instantiates the shared SSA library and bases the existing SSA classes on it. There are a small number of test changes in the last commit, which I want to either fix or understand before moving on to the next stage. This is most obvious in go/ql/test/library-tests/semmle/go/dataflow/SSA/SsaDefinition.expected, where we lose two SSA definitions. It looks like we fail to read from a captured variable back into the corresponding variable in the declaring container after a call. I actually think what's happening is that the write in the closure is being pruned because it doesn't seem to flow to a read. The go logic that we're replacing does this pruning as
liveAfterDef(bb, i, v) or v.isCaptured()
, which protects captured variables from being pruned.The next steps, once that is sorted out, is using the predicates provided by the shared SSA library, e.g. I think it would give us the first use, adjacent use, and localFlowStep predicates. After that, we also have to implement proper post-update nodes.